package cn.pop.hsp_system_v2.Controller;

import cn.pop.hsp_system_v2.Util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;


@Controller
public class managerController {

//    @Autowired
//    private TbUseService tbUseService;
//    //材料信息更改
//    @PostMapping(value = "/manager/wareHousingInfo/EditInfo")
//    public String SaveEditInfo(RedirectAttributes attr, Integer EditInfo, @ModelAttribute TbUse tbUse){
//        if(EditInfo!=null){
//            tbUse.setId(EditInfo);
//            boolean IsEditupdate=tbUseService.updateById(tbUse);
//            if(IsEditupdate){
//                attr.addAttribute("popInfo", true);
//                return "redirect:/manager/warehousingInfo";
//            }
//            attr.addAttribute("popInfo", false);
//            return "redirect:/manager/warehousingInfo";
//        }
//        attr.addAttribute("popInfo", false);
//        return "redirect:/manager/warehousingInfo";
//    }
//    //库存修改
//    @PostMapping("/manager/wareHousingInfo/Edit")
//    public String saveInfoNum(Integer Edit,@ModelAttribute TbUse tbUse,RedirectAttributes attr){
//        if(Edit!=null){
//            tbUse.setId(Edit);
//            boolean IsEditnumber=tbUseService.updateById(tbUse);
//            if(IsEditnumber){
//                attr.addAttribute("popNumber",true);
//                return "redirect:/manager/warehousingInfo";
//            }
//            attr.addAttribute("popNumber",false);
//            return "redirect:/manager/warehousingInfo";
//        }
//        attr.addAttribute("popNumber",false);
//        return "redirect:/manager/warehousingInfo";
//    }
//    //材料添加
//    @Autowired
//    private FileUtil fileUtil;
//    @PostMapping("/manager/wareHousingInfo/addUse")
//    public String addUse(@RequestParam("fileupload")MultipartFile file,TbUse use) throws Exception {
//        if(file!=null) {
//            String fileName = fileUtil.uploadFile(file);
//            use.setImages(fileName);
//            tbUseService.save(use);
//            return "redirect:/manager/warehousingInfo";
//        }
//        return "redirect:/manager/warehousingInfo";
//    }
//
//    //添加医生
//    @Autowired
//    private TbDocInfoService tbDocInfoService;
//    @PostMapping("/manager/doctorInfo/adddoc")
//    public String adddoc(TbDocInfo tbDocInfo){
//        if(tbDocInfo.getDocId()!=null&&tbDocInfo.getName()!=null&&tbDocInfo.getProtitle()!=null){
//            tbDocInfo.setPasswd(tbDocInfo.getDocId().toString());
//            boolean IsdocSave=tbDocInfoService.save(tbDocInfo);
//            if(IsdocSave){
//                System.out.println("添加医师成功,工号:"+tbDocInfo.getDocId());
//                return "redirect:/manager/doctorInfo";
//            }
//            System.out.println("添加医师失败"+tbDocInfo.getDocId());
//            return "redirect:/manager/doctorInfo";
//        }
//        return "redirect:/manager/doctorInfo";
//    }
//    //医师账户冻结\激活
//    @GetMapping("/manager/doctorInfo/status")
//    public String docstatus(Integer doc_id, Model model){
//         TbDocInfo tbDocInfo=tbDocInfoService.getById(doc_id);
//        if(tbDocInfo.getStatus()==1){
//            tbDocInfo.setStatus(0);
//            boolean updateById = tbDocInfoService.updateById(tbDocInfo);
//            if(updateById){
//                model.addAttribute("msg", "账户:"+tbDocInfo.getId()+"已冻结");
//                return "redirect:/manager/doctorInfo";
//            }
//            model.addAttribute("msg", "账户冻结失败");
//            return "redirect:/manager/doctorInfo";
//        }else if(tbDocInfo.getStatus()==0){
//            tbDocInfo.setStatus(1);
//            boolean updateById = tbDocInfoService.updateById(tbDocInfo);
//            if(updateById){
//                model.addAttribute("msg", "账户:"+tbDocInfo.getId()+"已激活");
//                return "redirect:/manager/doctorInfo";
//            }
//            model.addAttribute("msg", "账户冻结失败");
//            return "redirect:/manager/doctorInfo";
//        }
//        return "redirect:/manager/doctorInfo";
//    }
//    //重置医师密码
//    @GetMapping("/manager/doctorInfo/passwd")
//    public String resetPasswd(Integer doc_id,Model model){
//        TbDocInfo tbDocInfo = tbDocInfoService.getById(doc_id);
//        if(tbDocInfo!=null){
//            Integer docId = tbDocInfo.getDocId();
//            tbDocInfo.setPasswd(docId.toString());
//            boolean Isupdate = tbDocInfoService.updateById(tbDocInfo);
//            if (Isupdate){
//                model.addAttribute("msg", "密码重置成功,工号为:"+doc_id);
//                return "redirect:/manager/doctorInfo";
//            }
//        }
//        model.addAttribute("msg", "密码重置失败");
//        return "redirect:/manager/doctorInfo";
//    }

}
